package com.aidansmeaton;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.aidansmeaton.internet.ParseHelper;
import com.aidansmeaton.internet.PassengerNameValue;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
import arnodenhond.graphviewdemo.GraphView;

public class DeskActivity extends WebViewActivity {
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.desk);
		
		url = "http://www.airwaysim.com/game/Office";
		loadWebView();
						
	}
	
	public void passengers(View v){
		
		/*
		Intent i = new Intent(getBaseContext(), GraphViewDemo.class);
        startActivity(i);
        finish();
        */
		
		String source = ParseHelper.getSource("http://www.airwaysim.com/game/tmp/chart_game96_airline2137_pax.xml");
		
		/*
		TextView tv1 = (TextView) findViewById(R.id.info1);
		tv1.setText(source);
		*/
		
		PassengerNameValue chartValues = new PassengerNameValue(source);
		float[] values = chartValues.getValues();
		String[] verlabels = chartValues.getVertical_labels();
		String[] horlabels = chartValues.getHorizontal_labels();
		GraphView graphView = new GraphView(this, values, "Passengers / Week", horlabels, verlabels, GraphView.LINE);
		setContentView(graphView);
		
	}
	
	public void pretaxProfit(View v){
		
		/*
		Intent i = new Intent(getBaseContext(), GraphViewDemo.class);
        startActivity(i);
        finish();
        */
		
		String source = ParseHelper.getSource("http://www.airwaysim.com/game/tmp/chart_game96_airline2137_incomesheet_Result1.xml");
		
		/*
		TextView tv1 = (TextView) findViewById(R.id.info1);
		tv1.setText(source);
		*/
		
		PassengerNameValue chartValues = new PassengerNameValue(source);
		float[] values = chartValues.getValues();
		String[] verlabels = chartValues.getVertical_labels();
		String[] horlabels = chartValues.getHorizontal_labels();
		GraphView graphView = new GraphView(this, values, "Passengers / Week", horlabels, verlabels, GraphView.LINE);
		setContentView(graphView);
		
	}

	@Override
	protected void loadWebView() {
		
		webview = new WebView(myApp);
		webview.getSettings().setJavaScriptEnabled(true);
		webview.addJavascriptInterface(new OverviewJavaScriptInterface(), "HTMLOUT");
		webview.getSettings().setSaveFormData(true);
		webview.getSettings().setBuiltInZoomControls(true);
		webview.setWebViewClient(new HTMLWebViewClient());
		webview.loadUrl(url); // 'html' instance variable is also loaded here
		
	}
	
	protected class OverviewJavaScriptInterface	{
		
	    public void showHTML(String pageHTML) {
	    	html = pageHTML;
	    }
	}
}
